#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start VLC service
# ==============================================================================
# shellcheck disable=SC2155
readonly PASSWORD="$(cat /data/secret)"

bashio::log.info "Waiting for PulseAudio socket to become available..."

while [ ! -S "/run/audio/pulse.sock" ]
do
    sleep 1
done

bashio::log.info "PulseAudio socket available, starting VLC"

# Send out discovery information to Home Assistant
/etc/s6-overlay/scripts/vlc-discovery &

# Run daemon
exec cvlc -I http --no-dbus --extraintf telnet --http-host 127.0.0.1 --http-password "INGRESS" --telnet-password "${PASSWORD}" --aout=pulse
